﻿using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2025-02-22
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 配置表
    /// </summary>
    [Verify]
    [Route("business/CksConfig")]
    [ApiExplorerSettings(GroupName = "business")]
    public class CksConfigController : BaseController
    {
        /// <summary>
        /// 配置表接口
        /// </summary>
        private readonly ICksConfigService _CksConfigService;

        public CksConfigController(ICksConfigService CksConfigService)
        {
            _CksConfigService = CksConfigService;
        }

        /// <summary>
        /// 查询配置表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "cksconfig:list")]
        public IActionResult QueryCksConfig([FromQuery] CksConfigQueryDto parm)
        {
            var response = _CksConfigService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询配置表详情
        /// </summary>
        /// <param name="ConfigId"></param>
        /// <returns></returns>
        [HttpGet("{ConfigId}")]
        [ActionPermissionFilter(Permission = "cksconfig:query")]
        public IActionResult GetCksConfig(int ConfigId)
        {
            var response = _CksConfigService.GetInfo(ConfigId);

            var info = response.Adapt<CksConfigDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加配置表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "cksconfig:add")]
        [Log(Title = "配置表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCksConfig([FromBody] CksConfigDto parm)
        {
            var modal = parm.Adapt<CksConfig>().ToCreate(HttpContext);

            var response = _CksConfigService.AddCksConfig(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新配置表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "cksconfig:edit")]
        [Log(Title = "配置表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCksConfig([FromBody] CksConfigDto parm)
        {
            var modal = parm.Adapt<CksConfig>().ToUpdate(HttpContext);
            var response = _CksConfigService.UpdateCksConfig(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除配置表
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "cksconfig:delete")]
        [Log(Title = "配置表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCksConfig([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CksConfigService.Delete(idArr));
        }

    }
}